package com.iflytek.cuckoo.controller;

import com.iflytek.cuckoo.entity.Message;
import com.iflytek.cuckoo.entity.User;
import com.iflytek.cuckoo.kafka.KafkaSender;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p><一句话功能简述>
 * <p><功能详细描述>
 * <p>
 * <p>Copyright (c) 2018, liangzhang14@iflytek.com All Rights Reserve</p>
 * <p>Company : 科大讯飞</p>
 *
 * @author liangzhang14
 * @version [V1.0, 2019年09月06日 15:39]
 * @see [相关类/方法]
 */
@Slf4j
@RestController
@RequestMapping("/kafka")
public class KafkaController {
    @Autowired
    private KafkaSender sender;

    @RequestMapping(value = "send/{message}", method = RequestMethod.GET)
    public String sendKafka(@PathVariable("message") String message) {
        try {
            log.info("kafka的消息={}", message);
            sender.send(message);
            log.info("发送kafka成功.");
            return "sucess";
        } catch (Exception e) {

            log.error("发送kafka失败", e);
            return "fail";
        }
    }

    @RequestMapping(value = "/ssss", method = RequestMethod.PUT)
    public String sendKafka1(@RequestBody Message message) {
        try {
            log.info("kafka的消息={}", message);
            sender.send(message);
            log.info("发送kafka成功.");
            return "sucess";
        } catch (Exception e) {

            log.error("发送kafka失败", e);
            return "fail";
        }
    }
}